package com.dk.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dk.data.Result;
import com.dk.entity.DtModel;
import com.dk.service.IDtModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("model")
@Api(value = "回收商品型号管理接口")
public class ModelController {

    @Autowired
    private IDtModelService modelService;

    @GetMapping
    @ApiOperation(value = "回收商品型号分页查询")
    //参数类型：paramType body表示@RequestBody接收的参数，path表示路径传参/{xx},query表示@RequestParam接受的参数
    @ApiImplicitParams({
            @ApiImplicitParam(name="pageNum",value = "当前页数",required = true,paramType = "query"),
            @ApiImplicitParam(name="pageSize",value = "每页条数",required = true,paramType = "query")
    })
    public Result getModels(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize",defaultValue = "3") Integer pageSize){
        IPage<DtModel> page = modelService.getModels(pageNum,pageSize);
        return Result.ok().setData(page);
    }

    @PostMapping
    @ApiOperation(value = "回收商品型号增加")
    //参数类型：paramType body表示@RequestBody接收的参数，path表示路径传参/{xx},query表示@RequestParam接受的参数
    @ApiImplicitParam(name="model",value = "回收商品型号实体类",required = true,paramType = "body")
    public Result add(@RequestBody DtModel model){
        modelService.add(model);
        return Result.ok();
    }

    @DeleteMapping
    @ApiOperation(value = "根据id删除回收商品型号")
    //参数类型：paramType body表示@RequestBody接收的参数，path表示路径传参/{xx},query表示@RequestParam接受的参数
    @ApiImplicitParam(name="id",value = "回收商品型号id",required = true,paramType = "query")
    public Result delete(@RequestParam("id") Integer id){
        modelService.delete(id);
        return Result.ok();
    }

    @PutMapping
    @ApiOperation(value = "根据id修改回收商品型号")
    //参数类型：paramType body表示@RequestBody接收的参数，path表示路径传参/{xx},query表示@RequestParam接受的参数
    @ApiImplicitParam(name="model",value = "回收商品型号实体类",required = true,paramType = "body")
    public Result update(@RequestBody DtModel model){
        modelService.update(model);
        return Result.ok();
    }



}
